//
//  UIFont+Addition.m
//  YSProject
//
//  Created by 昱胜 on 2021/12/21.
//

#import "UIFont+Addition.h"

@implementation UIFont (Addition)

+ (UIFont *)ys_fontWithSize:(CGFloat)size {
    
   
    return [self ys_mainFontWithName:[self ys_mainFontName] Size:size];
    
}
+ (UIFont *)ys_boldFontWithSize:(CGFloat )size {
    
    return [self ys_mainFontWithName:[self ys_mainBoldFontName] Size:size];
}
+ (UIFont *)ys_mediumFontWithSize:(CGFloat )size {
    
    return [self ys_mainFontWithName:[self ys_mainMediumFontName] Size:size];
}

+ (UIFont *)ys_bahnschriftFontWithSize:(CGFloat )size {
    
    return [self ys_mainFontWithName:[self ys_mainBahnschriftFontName] Size:size];
}

+ (UIFont *)ys_mainFontWithName:(NSString *)name Size:(CGFloat )size {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0) {
        UIFont *font = [UIFont fontWithName:name size:size];
        if (!font) {
            if ([name isEqualToString:[self ys_mainFontName]]) {
                font = [UIFont fontWithName:[self ys_mainFontName] size:size];
                
            } else if ([name isEqualToString:[self ys_mainBoldFontName]]) {
                font = [UIFont fontWithName:[self ys_mainBoldFontName] size:size];
                
            } else if ([name isEqualToString:[self ys_mainMediumFontName]]) {
                font = [UIFont fontWithName:[self ys_mainMediumFontName] size:size];
                
            } else if ([name isEqualToString:[self ys_mainBahnschriftFontName]]) {
                font = [UIFont fontWithName:[self ys_mainBahnschriftFontName] size:size];
            } else {
                font =[UIFont systemFontOfSize:size];
            }
        }
        return font;
    }else {
        if ([name isEqualToString:[self ys_mainBoldFontName]]) {
            return [UIFont boldSystemFontOfSize:size];
        }else {
            return [UIFont systemFontOfSize:size];
        }
        
    }
}

+ (NSString *)ys_mainFontName {
    return @"PingFangSC-Regular";
}
+ (NSString *)ys_mainBoldFontName {
    return @"PingFangSC-Semibold";
}
+ (NSString *)ys_mainMediumFontName {
    return @"PingFangSC-Regular";
}
+ (NSString *)ys_mainBahnschriftFontName {
    return @"bahnschrift";
}
+ (void)allFontFamily {
    for(NSString *fontfamilyname in [UIFont familyNames])
    {
        NSLog(@"family:'%@'",fontfamilyname);
        for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])
        {
            NSLog(@"\tfont:'%@'",fontName);
        }
        NSLog(@"-------------");
    }

}


@end
